﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vit.DataAccess;
using Vit.SchemaExplorer;

namespace Vit.Data
{
    public class EntityRowMapper<TEntity> : IRowMapper<TEntity> where TEntity : EntityBase, new()
    {
        #region IRowMapper<TEntity> Members

        public virtual TEntity MapRow(IDataRecord row)
        {
            TEntity entity = new TEntity();
            for(int i=0; i< row.FieldCount; i++)
            {
                string name = row.GetName(i);
                object val = row.GetValue(i);
                entity.SetProperty(name, val,  EntityState.Original, EntityState.Original);
            }
            return entity;
        }

        #endregion
    }
}
